;; -*- mode: lisp-interaction; coding: gbk-dos; -*-
;; Carson <uvhchina@gmail.com>

(require 'tabbar)

;; tabbar 2D look, it's perfect.
(custom-set-faces
'(tabbar-default-face
  ((t(:inherit variable-pitch :height 0.8 :foreground "black" :background
"lightgrey" )))
  "Default face used in the tab bar."
  :group 'tabbar)

'(tabbar-unselected-face
  ((t(:inherit tabbar-default-face )))
  "Face used for uselected tabs."
  :group 'tabbar)

'(tabbar-selected-face
  ((t(:inherit tabbar-default-face :box (:line-width 1 :color "lightyelllow"
:style pressed-button) :foreground "blue")))
  "Face used for the selected tab."
  :group 'tabbar)

'(tabbar-separator-face
  ((t(:inherit tabbar-default-face :height 0.2)))
  "Face used for the select mode button."
  :group 'tabbar)

'(tabbar-button-face
  ((t(:inherit tabbar-default-face :box (:line-width 1 :color "white" :style
released-button) :foreground "dark red")))
  "Face used for the select mode button."
  :group 'tabbar)
)

;;;;;;;;;;;; hook
(setq tabbar-buffer-groups-function 'tabbar-buffer-ignore-groups)

(defun tabbar-buffer-ignore-groups (buffer)
  "Return the list of group names BUFFER belongs to.
Return only one group for each buffer."
  (with-current-buffer (get-buffer buffer)
    (cond
     ((or (get-buffer-process (current-buffer))
          (memq major-mode
                '(comint-mode compilation-mode)))
      '("Process")
      )
     
     ((member (buffer-name)
              '("*scratch*" "*Messages*" "*Completions*"))
      '("Common")
      )
     ((eq major-mode 'dired-mode)
      '("Dired")
      )
     ((memq major-mode
            '(help-mode apropos-mode Info-mode Man-mode))
      '("Help")
      )
     ((memq major-mode
            '(rmail-mode
              rmail-edit-mode vm-summary-mode vm-mode mail-mode
              mh-letter-mode mh-show-mode mh-folder-mode
              gnus-summary-mode message-mode gnus-group-mode
              gnus-article-mode score-mode gnus-browse-killed-mode))
      '("Mail")
      )
     (t
      (list 
       "default"  ;; no-grouping
       (if (and (stringp mode-name) (string-match "[^ ]" mode-name))
           mode-name
         (symbol-name major-mode)))
      )
     )))

;;;;;;;;;;;; hook
(tabbar-mode t)

;;(global-set-key [(control f10)]       'tabbar-local-mode)
(global-set-key [(control .)] 'tabbar-forward)

(global-set-key (kbd "s-p")           'tabbar-backward-group)
(global-set-key (kbd "s-n")           'tabbar-forward-group)
(global-set-key (kbd "s-j")           'tabbar-backward)
(global-set-key (kbd "s-k")           'tabbar-forward)

(setq tabbar-cycling-scope (quote tabs))

(require 'ido)
(ido-mode 'buffer)
(setq ido-enable-flex-matching t)
(setq ido-save-directory-list-file (concat my-emacs-conf-path ".ido-last"))
(defun ido-save-history nil)
;;(ido-mode t)
(global-set-key (kbd "C-x f") 'find-file-at-point)

(require 'ibuffer)
(setq ibuffer-shrink-to-minimum-size t)
(setq ibuffer-always-show-last-buffer nil)
(setq ibuffer-sorting-mode 'recency)
(setq ibuffer-use-header-line t)
;;(global-set-key [(f12)] 'ibuffer)
(autoload 'ibuffer "ibuffer" "List buffers." t)
(global-set-key (kbd "C-x C-b") 'ibuffer)

(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)

(require 'pager)
(global-set-key "\C-v"	   'scroll-up)
(global-set-key [next] 	   'scroll-up)
(global-set-key "\ev"	   'scroll-down)
(global-set-key [prior]	   'scroll-down)
(global-set-key '[M-up]    'pager-row-up)
(global-set-key '[M-kp-8]  'pager-row-up)
(global-set-key '[M-down]  'pager-row-down)
(global-set-key '[M-kp-2]  'pager-row-down)
